# Maintainer: Sébastien Luttringer
# Contributor: Judd Vinet <jvinet@zeroflux.org>

pkgname=ipvsadm
pkgver=1.31
pkgrel=2
pkgdesc='The IP Virtual Server administration utility'
arch=('loong64' 'x86_64')
url='http://www.linuxvirtualserver.org/software/ipvs.html'
license=('GPL2')
depends=('glibc' 'libnl' 'popt' 'bash')
backup=("etc/$pkgname.conf")
options=('!makeflags')
install=$pkgname.install
source=("https://kernel.org/pub/linux/utils/kernel/ipvsadm/$pkgname-$pkgver.tar."{xz,sign}
        "$pkgname.systemd"
        "$pkgname.service"
        '01-use-CFLAGS-and-LDFLAGS-environment.patch')
validpgpkeys=('D893F72888349DB4F170F9A23A554D033B37BCED') # Jesper Dangaard Brouer (RedHat)
# upstream provides sha256sums of release
sha256sums=('1a0a5e25b5a1226435d2fb76341656f83a710183aebb0d204db39c0ec3bedfdb'
            'SKIP'
            '4960ea254128347b03665d51817f29cb643cf2ebca13f5f46649257552ad3ceb'
            '25506d07f412cccab6f2f3a2a1900d5eeda27bc58602d14f44910c4e036b5341'
            '3016d22a0b5d8e735676ea2ab8c9d718fe6254e22fca5cec0a753fe57f34c4f9')

prepare() {
  cd $pkgname-$pkgver
  # apply patch from the source array (should be a pacman feature)
  local src
  for src in "${source[@]}"; do
    src="${src%%::*}"
    src="${src##*/}"
    [[ $src = *.patch ]] || continue
    echo "Applying patch $src..."
    patch -Np1 < "../$src"
  done
  :
}

build() {
  cd $pkgname-$pkgver
  make
}

package() {
  pushd $pkgname-$pkgver
  make \
    BUILD_ROOT="$pkgdir" \
    MANDIR=usr/share/man \
    SBIN="$pkgdir/usr/bin" \
    INIT="$pkgdir/etc/rc.d" \
    install
  popd
  # systemd
  install -Dm 755 $pkgname.systemd \
    "$pkgdir/usr/lib/systemd/scripts/$pkgname"
  install -Dm 644 $pkgname.service \
    "$pkgdir/usr/lib/systemd/system/$pkgname.service"
  # remove legacy init system
  rm -rf "$pkgdir/etc/rc.d"
  # default config file
  install -Dm 644 /dev/null "$pkgdir/etc/$pkgname.conf"
}

# vim:set ts=2 sw=2 et:
